<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
		<title>趣引流主页</title>
		<link rel="stylesheet" type="text/css" href="./css/api.css" />
	</head>
	<body>
		<div id="app">

		</div>
	</body>
	<script type="text/javascript" src="./script/api.js"></script>
	<script type="text/javascript" src="./script/app.js"></script>
	<script type="text/javascript" src="./script/vue.js"></script>
	<script type="text/javascript">
		var vm;
		apiready = function() {
			api.removeLaunchView();
			api.addEventListener({
				name: 'smartupdatefinish'
			}, function(ret, err) {
				api.rebootApp();
			});
			// setStyle();
			openUserGroup();
			startVue();
			setTimeout(function() {
				reloadPage();
			}, 300);
			api.addEventListener({
				name: 'keyback'
			}, function(ret, err) {
				if (vm.root) {
					exitApp();
				} else {
					qhSelect(0);
				}
			});
			api.addEventListener({
				name: 'swiperight'
			}, function(ret, err) {
				if (vm.root) {
					exitApp();
				} else {
					qhSelect(0);
				}
			});
		};

		function startVue() {
			vm = new Vue({
				el: "#app",
				data: {
					root: true,
					exit: false,
				},
				methods: {
					getSwitch: function(num) {
						if (num == 2) {
							if (!is_login()) {
								api.openWin({
									name: 'login',
									reload: true,
									url: './html/personal/login.html',
								});
							} else {
								goWin("fabu", "./html/home/fabu.html", {});
								return;
							}
						}
						if (num == 3) {
							if (!is_login()) {
								api.openWin({
									name: 'login',
									reload: true,
									url: './html/personal/login.html',
								});
							} else {
								goWin("woyaozhuanqian", "./html/home/woyaozhuanqian.html", {});
								return;
							}
						}
						if (num == 4) {
							if (!is_login()) {
								api.openWin({
									name: 'login',
									reload: true,
									url: './html/personal/login.html',
								});
							} else {
								goWin("personal", "./html/personal/personal.html", {});
								return;
							}
						}
						api.setFrameGroupIndex({
							name: 'first',
							index: num,
							reload:true
						});
					}
				}
			})
		}

		function qhSelect(index) {
			var NVTabBar = api.require('NVTabBar');
			NVTabBar.setSelect({
				index: index,
				selected: true
			});
			api.setFrameGroupIndex({
				name: 'first',
				index: index
			});
		}

		function setSelect(index) {
			var NVTabBar = api.require('NVTabBar');
			NVTabBar.setSelect({
				index: index,
				selected: true
			});
		}

		function openUserGroup() {
			if (!is_login()) {
				api.openWin({
					name: 'login',
					reload: true,
					url: './html/personal/login.html',
				});
			}
			// return goWin('upproduct','./upproduct.html',{});
			api.openFrameGroup({
				name: 'first',
				scrollEnabled: false,
				preload: 0,
				rect: {
					x: 0,
					y: 0,
					w: 'auto',
					h: 'auto',
				},
				frames: [{
						name: 'home',
						url: './html/home/home.html',
						bgColor: '#fff',
						bounces: false
					},
					{
						name: 'jiafencenter',
						url: './html/home/jiafencenter.html',
						bgColor: '#fff',
						bounces: false
					},
					{
						name: 'fabu',
						url: './html/home/fabu.html',
						bgColor: '#fff',
						bounces: false
					},
					{
						name: 'woyaozhuanqian',
						url: './html/home/woyaozhuanqian.html',
						bgColor: '#fff',
						allowEdit: true,
						bounces: false
					},
					{
						name: 'personal',
						// url: './html/person/yewucenter.html',
						url: './html/personal/personal.html',
						bgColor: '#fff',
						bounces: false
					}
				]
			}, function(ret, err) {
				if (ret.index == 0) {
					vm.root = true;
				} else {
					vm.root = false;
				}
			});
		}

		function reloadPage() {
			NVTabBar(function(ret) {
				vm.getSwitch(ret);
			});
		}

		function hideBar() {
			var NVTabBar = api.require('NVTabBar');
			NVTabBar.hide({
				animation: true
			});
		}

		function showBar() {
			var NVTabBar = api.require('NVTabBar');
			NVTabBar.show({
				animation: true
			});
		}

		function exitApp() {
			if (vm.exit) {
				api.closeWidget({
					silent: true,
				});
				// api.toLauncher();
			} else {
				api.execScript({
					name: 'root',
					frameName: 'home',
					script: 'showAlert();'
				});
				vm.exit = true;
				setTimeout(function() {
					api.execScript({
						name: 'root',
						frameName: 'home',
						script: 'hideAlert();'
					});
					vm.exit = false;
				}, 1500);
			}
		}
	</script>

</html>
